package com.cupdata.zicon.decorator;

import org.junit.Test;

import java.io.UnsupportedEncodingException;

/**
 * 装饰者模式测试类
 */
public class DecoratorTest {
    @Test
    public void decoratorTest01(){
        //原构件要执行的业务逻辑
        Component concreteComponent = new ConcreteComponent();
        //在原构件上增加了新的业务逻辑
        Component newConcreteComponent = new ConcreteDecorator(concreteComponent);
        //执行合并后的业务逻辑
        newConcreteComponent.operation();
    }

    @Test
    public void decoratorTest02(){
        String str=null;
        try {
            str= new String("测试字符串".getBytes("UTF-8"),"ISO8859-1");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        //原构件要执行的业务逻辑
        Component concreteComponent = new ConcreteComponent();
        String result = concreteComponent.getParam(str);
        System.out.println("源字符串:"+result);
        //开启偷天换日的功能
        Component newConcreteComponent = new ConcreteDecorator(concreteComponent);
        String result1 = newConcreteComponent.getParam(str);
        System.out.println("新字符串:"+result1);
    }


}
